import json

from ronglian_sms_sdk import SmsSDK

accId = '2c94811c936de29c01937052c1b60031'
accToken = '4185028f86b04c15b97a88eab72d8f62'
appId = '2c94811c936de29c0193715f0f7900d3'

def send_message(mobile, code, time):
    sdk = SmsSDK(accId, accToken, appId)
    tid = '1'
    mobile = mobile
    datas = (code, time)
    resp = sdk.sendMessage(tid, mobile, datas)
    print(datas[0])
    return resp

# def send_message(phone,code,time):
#     sdk = SmsSDK(accId, accToken, appId)
#     tid = '1'
#     mobile = phone
#     datas = (code,time)
#     resp = json.loads(sdk.sendMessage(tid, mobile, datas))#默认的返回的是一个json格式 的字符串
#     if resp['statusCode']=='000000':
#         return True
#     else:
#         return False
# print(send_message('18749812616','1234',1))
# class SendCode(APIView):
#     def post(self,request):
#         phone=request.data.get('account')
#         # if re.match(r"^1[3456789]\d{9}$",phone):
#         code=str(random.randint(10000,99999))
#         if send_message(phone,code):
#             redistoll.setex(phone, code, 60 * 2)
#             return Response({'msg': "发送成功"})
#         else:
#             return Response({'msg':"发送失败"})